

class Main extends eui.UILayer {


    protected createChildren(): void {
        super.createChildren();

        egret.lifecycle.addLifecycleListener((context) => {
            // custom lifecycle plugin
        })

        egret.lifecycle.onPause = () => {
            egret.ticker.pause();
        }

        egret.lifecycle.onResume = () => {
            egret.ticker.resume();
        }

        //inject the custom material parser
        //注入自定义的素材解析器
        let assetAdapter = new AssetAdapter();
        egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
        egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());


        this.runGame().catch(e => {
            console.log(e);
        })
    }

    private async runGame() {
        await RES.loadConfig("resource/default.res.json", "resource/");
        await this.loadTheme();
        // await this.loadResource()
           this.createGameScene();


    }

    // private async loadResource() {
    //     try {
    //         const loadingView = new Loading2();
    //         this.stage.addChild(loadingView);

    //         await RES.loadGroup("preload", 0, loadingView);
    //         // this.stage.removeChild(loadingView);
    //     }
    //     catch (e) {
    //         console.error(e);
    //     }
    // }

    private loadTheme() {
        return new Promise((resolve, reject) => {
            //加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
            let theme = new eui.Theme("resource/default.thm.json", this.stage);
            theme.addEventListener(eui.UIEvent.COMPLETE, () => {
                resolve();
            }, this);

        })
    }

    private textfield: egret.TextField;
    /**
     * 创建场景界面
     * Create scene interface
     */
    protected createGameScene(): void {
<<<<<<< HEAD
        // 如何加载声音

        // let Load = new Loading();
        // this.addChild(Load);
        //制造一个石头的图片出来
        // let stone = new Stone();
        // this.addChild(stone);
        //调用场景管理类来加载场景
        let musicBtn = new MusicBtn();
		this.stage.addChild(musicBtn);
        musicBtn.name = "musicBtn";
        SceneManger.createObj(this.stage).loadScene("gameone", GameMain1);//前者是资源组名，后者是场景管理类
        
        // let GMin = new GameMain1();
        // this.addChild(GMin);
        //调用场景管理类来加载场景
        // let buton1 = new GameMain1().button1;

        // buton1.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
        //     alert("开始啦")
        // }, this)
        // SceneManger.createObj(this.stage).loadScene("GameMain2", GameMain2);

        // setTimeout(()=>{
        //     SceneManger.createObj(this.stage).loadScene("musicplay",Player);
        // },2000)
        /**
         * 点击按钮
         * Click the button
         */
=======
        //调用场景管理类来加载场景
        SceneManger.createObj(this.stage).loadScene("gameone",GameMain1);//前者是资源组名，后者是场景管理类
>>>>>>> c25664aa5bdd32dd0284b6cebb599dfcdfc66ea3
    }

    // static sound =new egret.Sound(); 
    // static mySound;
    static soundChannel;
    static sound;
    
    private onButtonClick(e: egret.TouchEvent) {
        let panel = new eui.Panel();
        panel.title = "Title";
        panel.horizontalCenter = 0;
        panel.verticalCenter = 0;
        this.addChild(panel);
    }
}
